
package com.amado.sprintboot.redscache.service.impl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import com.amado.sprintboot.redscache.entity.User;
import com.amado.sprintboot.redscache.service.UserService;

/**
 * @author wangyl-910
 * @description
 * @date 2018/2/26
 * @see
 */
@Service("UserServiceSpringCacheRedisImpl")
public class UserServiceSpringCacheRedisImpl implements UserService {

	private static final Logger LOGGER = LoggerFactory.getLogger(UserServiceSpringCacheRedisImpl.class);

	@Override
	@Cacheable(cacheNames = "user", key = "#userId")
	public User getUser(String userId) {
		User user = new User();
		user.setUserId(userId);
		user.setName("name");
		LOGGER.info("getUser USER:{}", user);
		return user;
	}

	@Override
	@CacheEvict(cacheNames = "user", key = "#userId")
	public void deleteUser(String userId) {
		LOGGER.info("deleteUser USER:{}", userId);
	}

	@Override
	@CacheEvict(cacheNames = "user", key = "#record.userId")
	public void upateUser(User record) {
		LOGGER.info("deleteUser USER:{}", record);
	}
}
